#ifndef MARKER_H
#define MARKER_H

#include <QObject>
#include <QPoint>
#include <QRect>
#include <QBitmap>
#include <QDebug>
#include <qmath.h>

#define CONST_PI 3.14159265359

struct LineType
{
    //具体参照HPGL英文版手册216页 当LT没有设置值时,线型为实线
    bool bDefault;//LT是否设置值
    int nLinetype;//线型 取值为-8~8 ，99   =0 实线    =1 虚线
    int nPatternLength;//图案长度 缺省为P1、P2距离的4%
    int nMode;//0相对模式 缺省值 解释为P1、P2距离的百分比 1绝对模式，以毫米解释图案长度
};


class CBitmapInfo
{
public:
    //原始读取的的坐标
    QPoint m_ptPostLU; //位图的左上角在整个图中的XY位置
    QPoint m_ptPostLD; //位图的左下角在整个图中的XY位置
    QPoint m_ptPostRU; //位图的右上角在整个图中的XY位置
    QPoint m_ptPostRD; //位图的右下角在整个图中的XY位置

    //换算后的坐标
    QPoint m_ptAbPostLU; //位图的左上角在整个图中的XY位置
    QPoint m_ptAbPostLD; //位图的左下角在整个图中的XY位置
    QPoint m_ptAbPostRU; //位图的右上角在整个图中的XY位置
    QPoint m_ptAbPostRD; //位图的右下角在整个图中的XY位置

    int m_iTransparent;//为1时则为透明显示; 为0则为非透明显示
    int m_iBKColor;//背景颜色(在透明显示时背景颜色的点将不被显示)

    int m_iWidth;// GDI+中BitmapData的Width,单位：像素
    int m_iHeight;//GDI+中BitmapData的Height,单位：像素
    int m_iStride;//GDI+中BitmapData的Stride(每行的字节数)
    int m_iPixelFormat;//GDI+中BitmapData的PixelFormat

    int m_iBytes;//int压缩后位图数据大小(字节数)
    QBitmap m_pBitmap;//位图数据(压缩后的位图数据)

    CBitmapInfo()
    {
        m_ptPostLU = QPoint(0,0);
        m_ptPostLD = QPoint(0,0);
        m_ptPostRU = QPoint(0,0);
        m_ptPostRD = QPoint(0,0);
        m_ptAbPostLU = QPoint(0,0);
        m_ptAbPostLD = QPoint(0,0);
        m_ptAbPostRU = QPoint(0,0);
        m_ptAbPostRD = QPoint(0,0);
        m_iTransparent = 0;
        m_iBKColor = 0;
        m_iWidth = 0;
        m_iHeight = 0;
        m_iStride = 0;
        m_iPixelFormat = 1;
        m_iBytes = 0;
        //m_pBitmap = NULL;

    }
    ~CBitmapInfo() {}
    CBitmapInfo operator=(const CBitmapInfo &a)
    {
        m_ptPostLU = a.m_ptPostLU;
        m_ptPostLD = a.m_ptPostLD;
        m_ptPostRU = a.m_ptPostRU;
        m_ptPostRD = a.m_ptPostRD;
        m_ptAbPostLU = a.m_ptAbPostLU;
        m_ptAbPostLD = a.m_ptAbPostLD;
        m_ptAbPostRU = a.m_ptAbPostRU;
        m_ptAbPostRD = a.m_ptAbPostRD;
        m_iTransparent = a.m_iTransparent;
        m_iBKColor = a.m_iBKColor;
        m_iWidth = a.m_iWidth;
        m_iHeight = a.m_iHeight;
        m_iStride = a.m_iStride;
        m_iPixelFormat = a.m_iPixelFormat;
        m_iBytes = a.m_iBytes;
        m_pBitmap = a.m_pBitmap;
        return *this;
    }
};

class CRPArc
{
public:
    QPoint m_ptCenter;
    int m_nRadius;
    bool m_bCircle;//是圆还是圆弧1：圆 0 ：圆弧
    QPoint m_ptStart;//圆弧起始点
    QPoint m_ptEnd;//圆弧结束点

    CRPArc()
    {
        m_bCircle = true;
    }
    ~CRPArc() {}
    CRPArc(CRPArc &a)
    {
        m_ptCenter = a.m_ptCenter;
        m_nRadius = a.m_nRadius;
        m_bCircle = a.m_bCircle;
        m_ptStart = a.m_ptStart;
        m_ptEnd = a.m_ptEnd;
    }
    CRPArc operator=(const CRPArc &a)
    {
        m_ptCenter = a.m_ptCenter;
        m_nRadius = a.m_nRadius;
        m_bCircle = a.m_bCircle;
        m_ptStart = a.m_ptStart;
        m_ptEnd = a.m_ptEnd;
        return *this;
    }
};

class CRPText
{
public:
    QString m_strText;//字符串
    QString m_strFontName;//字体名称
    QPoint m_ptTextPos;//文字起点坐标
    double m_dTextAngle;//文字角度
    int m_nHeight;//文字高度
    int m_nWidth;//文字宽度
    int m_nWeight;//加粗
    bool m_bItalic;//斜体

    //文字坐标
    QPoint m_ptPostLU; //文字的左上角在整个图中的XY位置
    QPoint m_ptPostLD; //文字的左下角在整个图中的XY位置
    QPoint m_ptPostRU; //文字的右上角在整个图中的XY位置
    QPoint m_ptPostRD; //文字的右下角在整个图中的XY位置


    CRPText()
    {
        m_strText = "";
        m_strFontName = "";
        m_ptTextPos = QPoint(0,0);
        m_dTextAngle = 0;
        m_nHeight = 0;
        m_nWidth = 0;
        m_nWeight = 0;
        m_bItalic = false;
        m_ptPostLU = QPoint(0,0);
        m_ptPostLD = QPoint(0,0);
        m_ptPostRU = QPoint(0,0);
        m_ptPostRD = QPoint(0,0);
    }
    ~CRPText() {}
    CRPText(CRPText &a)
    {
        m_strText = a.m_strText;
        m_strFontName = a.m_strFontName;
        m_ptTextPos = a.m_ptTextPos;
        m_dTextAngle = a.m_dTextAngle;
        m_nHeight = a.m_nHeight;
        m_nWidth = a.m_nWidth;
        m_nWeight = a.m_nWeight;
        m_bItalic = a.m_bItalic;
        m_ptPostLU = a.m_ptPostLU;
        m_ptPostLD = a.m_ptPostLD;
        m_ptPostRU = a.m_ptPostRU;
        m_ptPostRD = a.m_ptPostRD;
    }
    CRPText operator=( const CRPText &a)
    {
        m_strText = a.m_strText;
        m_strFontName = a.m_strFontName;
        m_ptTextPos = a.m_ptTextPos;
        m_dTextAngle = a.m_dTextAngle;
        m_nHeight = a.m_nHeight;
        m_nWidth = a.m_nWidth;
        m_nWeight = a.m_nWeight;
        m_bItalic = a.m_bItalic;
        m_ptPostLU = a.m_ptPostLU;
        m_ptPostLD = a.m_ptPostLD;
        m_ptPostRU = a.m_ptPostRU;
        m_ptPostRD = a.m_ptPostRD;
        return *this;
    }
};

class CCode
{
public:
    int m_nLX;//左上角X位置
    int m_nLY;//左上角Y位置
    int m_nSizeX;//X方向大小
    int m_nSizeY;//Y方向大小
    int m_nAngle;//角度(逆时针方向为正),单位：0.01度
    int m_nType;//类型(0：条形码，1：二维码)
    int m_nCount;//字符串个数(字符串的字节数)
    QString m_strCode;//字符串
    QBitmap *m_pBitmap;//生成的位图数据

    CCode()
    {
        m_nLX = 0;
        m_nLY = 0;
        m_nSizeX = 0;
        m_nSizeY = 0;
        m_nAngle = 0;
        m_nType = 0;
        m_nCount = 0;
        m_strCode = "";
    }
    ~CCode() {}
    CCode(CCode &a)
    {
        m_nLX = a.m_nLX;
        m_nLY = a.m_nLY;
        m_nSizeX = a.m_nSizeX;
        m_nSizeY = a.m_nSizeY;
        m_nAngle = a.m_nAngle;
        m_nType = a.m_nType;
        m_nCount = a.m_nCount;
        m_strCode = a.m_strCode;
        m_pBitmap = a.m_pBitmap;
    }
    CCode operator=(const CCode &a)
    {
        m_nLX = a.m_nLX;
        m_nLY = a.m_nLY;
        m_nSizeX = a.m_nSizeX;
        m_nSizeY = a.m_nSizeY;
        m_nAngle = a.m_nAngle;
        m_nType = a.m_nType;
        m_nCount = a.m_nCount;
        m_strCode = a.m_strCode;
        m_pBitmap = a.m_pBitmap;
        return *this;
    }
};

class CNotch
{
public:
    QPoint m_ptStart;//剪口起点
    QPoint m_ptEnd;//剪口终点
    int m_nWidth;//剪口宽度
    int m_nNotchType;//剪口类型
    QPoint m_ptCorrect;//通过根据刀的X、Y偏移计算得出的实际落刀位置
    int m_nAngle;//根据交口起点和终点计算得出的角度(逆时针方向为正),单位：0.01度
    double angle_2(int startx,int starty,int endx,int endy);

    CNotch()
    {
        m_ptStart = QPoint(0,0);
        m_ptEnd = QPoint(0,0);
        m_nWidth = 0;;
        m_nNotchType = 0;
        m_ptCorrect = QPoint(0,0);
        m_nAngle = 0;
    }
    ~CNotch() {}
    CNotch(CNotch &a)
    {
        m_ptStart = a.m_ptStart;
        m_ptEnd = a.m_ptEnd;
        m_nWidth = a.m_nWidth;
        m_nNotchType = a.m_nNotchType;
        m_ptCorrect = a.m_ptCorrect;
        m_nAngle = a.m_nAngle;
    }
    CNotch operator=(const CNotch &a)
    {
        m_ptStart = a.m_ptStart;
        m_ptEnd = a.m_ptEnd;
        m_nWidth = a.m_nWidth;
        m_nNotchType = a.m_nNotchType;
        m_ptCorrect = a.m_ptCorrect;
        m_nAngle = a.m_nAngle;
        return *this;
    }
    void CovertToOutputByOffset(int nOffSetX,int nOffsetY);
    int IntOfLineCircle(double a,double b,double c,int xc,int yc,int nR,QPoint &lpptIntersection1,QPoint &lpptIntersection2);

};

class CDrill
{
public:
    QPoint m_pt;//冲孔的位置
    int m_nDrillType;//冲孔类型
    int m_nAngle;//冲孔的角度(逆时针方向为正),单位：0.01度

    CDrill()
    {
        m_pt = QPoint(0,0);
        m_nDrillType = 0;;
        m_nAngle = 0;
    }
    ~CDrill() {}
    CDrill(CDrill &a)
    {
        m_pt = a.m_pt;
        m_nDrillType = a.m_nDrillType;
        m_nAngle = a.m_nAngle;
    }
    CDrill operator=(const CDrill &a)
    {
        m_pt = a.m_pt;
        m_nDrillType = a.m_nDrillType;
        m_nAngle = a.m_nAngle;
        return *this;
    }
};

class CRPPolyline
{
public:
    int m_nDrawingType;//0:直线    1:位图      2:圆     3:文字     4:条形码、二维码    5:钻孔   6:剪口
    int m_nID;//标识切割线切割顺序 从0开始
    int m_nPenNo;
    bool m_bSelect;//是否处于选中状态，true：选中状态 false：未选中状态
    bool m_bPgEnd;//标识该切割线是该页的最后一条线
    int m_nComType;//补偿类型 0 无补偿 1向右（内）补偿 2向左（外）补偿

    CBitmapInfo m_bitmapInfo;
    CRPArc m_circle;
    CRPText m_text;
    CCode m_code;
    CDrill m_drill;
    CNotch m_notch;

    LineType m_lineType;
    QList<QPoint> m_listPoint;

    CRPPolyline()
    {
        m_nDrawingType = 0;
        m_nID = 0;
        m_nPenNo = 0;
        m_bSelect = false;
        m_bPgEnd = false;
        m_lineType.bDefault = true;
        m_listPoint.clear();
        m_nComType = 0;
    }
    ~CRPPolyline() {}
    CRPPolyline(const CRPPolyline &a)
    {
        m_nDrawingType = a.m_nDrawingType;
        m_nID = a.m_nID;
        m_nPenNo = a.m_nPenNo;
        m_bSelect = a.m_bSelect;
        m_bPgEnd = a.m_bPgEnd;
        m_lineType = a.m_lineType;
        m_listPoint.clear();
        m_listPoint.append(a.m_listPoint);
        m_text = a.m_text;
        m_nComType = a.m_nComType;
        m_circle = a.m_circle;
        m_text = a.m_text;
        m_code = a.m_code;
        m_notch = a.m_notch;
        m_drill = a.m_drill;
        m_bitmapInfo = a.m_bitmapInfo;
    }
    CRPPolyline operator=( const CRPPolyline &a)
    {
        m_nDrawingType = a.m_nDrawingType;
        m_nID = a.m_nID;
        m_nPenNo = a.m_nPenNo;
        m_bSelect = a.m_bSelect;
        m_bPgEnd = a.m_bPgEnd;
        m_lineType = a.m_lineType;
        m_listPoint.clear();
        m_listPoint.append(a.m_listPoint);
        m_text = a.m_text;
        m_nComType = a.m_nComType;
        m_circle = a.m_circle;
        m_text = a.m_text;
        m_code = a.m_code;
        m_notch = a.m_notch;
        m_drill = a.m_drill;
        m_bitmapInfo = a.m_bitmapInfo;
        return *this;
    }
};

class Marker : public QObject
{
    Q_OBJECT
public:
    explicit Marker(QObject *parent = 0);
    virtual ~Marker();
    Marker(const Marker &a);
    Marker operator=(const Marker &a);
    void Initialize();
    QRect GetRect();
    QRect RectofPolyline(const QList <QPoint> &listPoint);

    double m_iDPMM;  //长度数据单位:m_iDPMM(每毫米点)
    QList <CRPPolyline> m_listPolyline;  //切割的点链,单位:1/m_iDPMM mm, X向右为正，Y向上为正
    int m_nProducts;
    int m_nActualMatchRegions;
    int m_nMatchRegions;
    QString m_strProductCode;//产品型号


signals:

public slots:

};

#endif // MARKER_H
